package com.example.tosco;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.os.StrictMode;

public class WebService {

        public String executar(String sURL){
                URL url;
                HttpURLConnection connection = null;
                BufferedReader content = null;
                try {
                	StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                	StrictMode.setThreadPolicy(policy);
                	
                	
                        url = new URL("http://10.10.1.14/" + sURL);

                        connection = (HttpURLConnection) url.openConnection();
                        content = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                        
                        String line = null;
                        String retorno = "";
                        while((line=content.readLine())!=null){
                                retorno = retorno + line;
                        }
                        return retorno;
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        return null;
                } finally {
                        connection.disconnect();
                }
        }
        
        public void atualiza(){
        	String retorno = executar("tosco/atualiza.php");
        	
        	retorno = executar(retorno);
        	
        }
        
}